package cn.tedu.csmall.product.controller;


import cn.tedu.csmall.product.service.IBrandCategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 处理品牌与类别关联相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */

@Api(tags = "6.品牌与类别关联关联模块")
@RestController
@RequestMapping("/brand-category")
@Slf4j
public class BrandCategoryController {

    @Autowired
    IBrandCategoryService brandCategoryService;

    // http://localhost:9080/brand-category/bind
    @ApiOperation("绑定品牌与类别的关联")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParams({
            @ApiImplicitParam(name="brandId",value = "品牌id",required = true,dataType = "long"),
            @ApiImplicitParam(name="category",value = "类别id",required = true,dataType = "long")
    })
    @PostMapping("/bind")
    public JsonResult<Void> bind(@PathVariable Long brandId, Long categoryId){
        log.debug("开始处理【绑定品牌和类别的关联】请求，品牌id={}，类别id={}",brandId,categoryId);
        brandCategoryService.bind(brandId,categoryId);
        return JsonResult.ok();
    }

    // http://localhost:9080/brand-category/unbind
    @ApiOperation("绑定品牌与类别的关联")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParam(name="id",value = "解绑id",required = true,dataType = "long")
    @PostMapping("/unbind")
    public JsonResult<Void> unbind(@PathVariable Long id){
        log.debug("开始处理【解绑品牌和类别的关联】请求，解绑id={}",id);
        brandCategoryService.unbind(id);
        return JsonResult.ok();
    }
}
